package org.idea.iedis.framework.server.io.core.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author linhao
 * @Date created in 11:16 上午 2021/8/15
 */
public class BioServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(6378);
        while (true) {
            System.out.println("wait conn --------");
            Socket socket = serverSocket.accept();
            System.out.println("conn ok --------- " + System.currentTimeMillis());
            byte[] bytes = new byte[1024];
            System.out.println("wait data ---------");
            socket.getInputStream().read(bytes);
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    handleData();
                }
            });
            t.start();
            System.out.printf("data is {}" + new String(bytes));
        }
    }

    /**
     * 处理数据信息
     */
    public static void handleData(){
        System.out.println("handling data begin ----------");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("handling data end ----------");
    }

}
